#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author:Charles.chen
# createDate:2017/9/5
# Title:
# Tip:
from . import api
from flask import Response
from app.model import Sensor, SensorData
from app.dataManagement import dataService
from app.toolkit import commonUtil
from app.crontime.crontimeService import backUpSensorDataJob
from app.dataManagement.dataService import downLoadSensorDataBetweenDate
import json

@api.route("/testApi")
def apiTest():
    backUpSensorDataJob()
    return Response("123")
    pass


@api.route("/downloadFile")
def downloadFile():

    res = downLoadSensorDataBetweenDate(startDate=1505441416, endDate=1505442945)
    data = commonUtil.convertDbObjToDict(res, SensorData)
    def generate():
        for row in data:
            yield json.dumps(row) + '\n'
    return Response(generate(), mimetype='text/csv')
    pass




if __name__ == '__main__':
    pass